/*
 * index Javascript
 */

$(document).ready(function(){
	$("a.btn").live("click", function(){
		$(this).blur();
	});
	$("a.bluebtn").live("click", function(){
		$(this).blur();
	});
	$("a.whitebtn").live("click", function(){
		$(this).blur();
	});
	$("a",".aui_outer").live("click", function(){
		$(this).blur();
	});
	$("a","#headUI").click(function(){
		$(this).parent().parent().find(".on").removeClass("on");
		$(this).addClass("on");
	});
	$("a","#sideUl").live("click", function(){
		$(this).parent().parent().find(".on").removeClass("on");
		$(this).addClass("on");
	});
	if(role_status == "999"){
		$("a:eq(0)","#headUI").click();
	}
});

function emptyFrame(){
	frame_set_lhead("");
	frame_set_side("");
	frame_set_current("");
	frame_set_main('<iframe id="bottomRight" name="bottomRight" src="" style="border: 0px solid #B4C9C6;" frameborder="0" width="100%" height="100%" scrolling="auto"></iframe>');
	frame_set_pag("");
}
function frame_set_lhead(html){
	$("#lhead","#sidebar").html(html);
}
function frame_set_side(html){
	$("#sideUl","#sidebar").html(html);
}

function frame_set_main(html){
	$("#mainBox","#container").html(html);
}

function frame_set_current(html){
	$(".cur_main","#current").html(html);
}

function frame_set_pag(html){
	$(".pag_main","#pag").html(html);
}

//初始化 短信管理
function iniSms(code){
	emptyFrame();
	frame_set_lhead('管理菜单');
	frame_set_current('公告：<span style="color:red;">系统正在研发中...</span>');
	frame_set_pag('用户可用余额：1000 条.');
	loadMenuLeft(code);
	var hurl=$("li","#sideUl").find("a").attr("href");
	$("#bottomRight").attr("src",hurl);
}

//初始化 名片管理
function iniCard(){
	emptyFrame();
	frame_set_lhead('名片分组');
	frame_set_current('公告：<span style="color:red;">系统正在研发中...</span>');
	var thml_card_Panel='<table><tr><td><input type="button" id="btn_newCard" class="liteBlueBtn" onclick="bottomRight.newCard()" value="添加名片"></td>';
	thml_card_Panel+='<td><input type="button" id="" class="liteBlueBtn" onclick="bottomRight.deleteCard()" value="删除名片"></td>';
	thml_card_Panel+='<td><input type="button" id="" class="liteBlueBtn" onclick="bottomRight.newCardGroup()" value="添加分组"></td>';
	thml_card_Panel+='<td><input type="button" id="" class="liteBlueBtn" onclick="bottomRight.deleteCardGroup()" value="删除分组"></td>';
	thml_card_Panel+='<tr></table>';
	frame_set_pag('<div id="cardPanel">'+thml_card_Panel+'</div><div id="paginationDiv"></div>');
	loadCardLeft();
	
}

//根据menucode载入左侧菜单
function loadMenuLeft(menucode){
	$.ajax({
		url:"menuleft.do",
		type:"post",
		data:"menucode="+menucode+"&randomval="+ (new Date).getTime(),
		dataType:"json",
		async:false,
		success:function(data){	
			var dataList = data.listMenuInfo2;
			var sideUlContent="";
			$.each(dataList, function (i){
				if(i==0){
					sideUlContent+="<li><a class='on' href="+dataList[i].source+" target="+dataList[i].target+">"+dataList[i].menuname+"</a></li>";
				}else{
					sideUlContent+="<li><a href="+dataList[i].source+" target="+dataList[i].target+">"+dataList[i].menuname+"</a></li>";
				}
			});
			frame_set_side(sideUlContent);
		}
	 });
}

//加载名片
var user_cardGroupInfo={};
function loadCardLeft(){
	$.getJSON("get_business_card_group_info.do?_random="+(new Date()).getTime(),function(result){
		user_cardGroupInfo=result;
		var html = '<li><a href="card_box_frame.do?id=all" target="bottomRight" class="on">全部分组</a></li><li><a href="card_box_frame.do?id=nogroup" target="bottomRight">未分组</a></li>';
		$.each(result, function (i){
			html+='<li><a href="card_box_frame.do?id='+result[i].id+'" target="bottomRight">'+result[i].groupname+'</a></li>';
		});
		frame_set_side(html);
		var hurl=$("li","#sideUl").find("a").attr("href");
		$("#bottomRight").attr("src",hurl);
	});
}